const server = require('../../utils/server');
const common = require('../../utils/common');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    list: [],
    isEmpty: false
  },

  onLoad() {
    this.getMyFeedback()
    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline']
    })
  },

  getMyFeedback() {
    if (this.data.isLoading) return
    this.setData({ isLoading: true })
    server.postJSON(common.basePath + 'feedback/index', {
      page: this.data.page,
      count: 10
    }, res => {
      setTimeout(() => {
        this.setData({ isLoading: false })
      }, 100);
      wx.stopPullDownRefresh()
      const { errno, data, errmsg } = res.data;
      if (errno == '0') {
        if (data.length) {
          this.setData({
            list: this.data.page == 1 ? data : [...this.data.list, ...data],
            isNoMore: data.length < 10
          })
        } else {
          this.setData({
            isEmpty: this.data.page == 1
          })
        }
      } else {
        common.showErrorToast(errmsg);
      }
    })
  },

  // 查看详情
  checkDetail(e) {
    const info = this.data.list[e.currentTarget.dataset.index]
    
   
    wx.setStorageSync('myComplaint', info)
    common.navigateTo({ url: 'complaint?isCheck=1' })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.data.page = 1
    this.getMyFeedback()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.isNoMore || this.data.isLoading) return
    this.data.page += 1
    this.getMyFeedback()
  },

})